package org.swinglife.log.sys.appender;

import org.swinglife.log.sys.SLFile;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public  class SLFileAppender implements SLFile {



    @Override
    public void writerFile(String message, File f) {
        SimpleDateFormat dateFm = null;
        if (f.exists()) {
        } else {
            System.out.print("文件不存在");
            try {
                f.createNewFile();// 不存在则创建
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        try {
            BufferedWriter output = new BufferedWriter(new FileWriter(f,true));//true,则追加写入text文本
            dateFm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //格式化当前系统日期
            output.write(dateFm.format(new Date())+""+message);
            output.write("\r\n");//换行
            output.flush();
            output.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
